﻿{include file="public/header" /}
<title>权限管理</title>
</head>

<body>
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 权限管理
		<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
	<div class="page-container">
		<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="chk(this)" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		<a href="javascript:;" onclick="admin_permission_add('添加权限节点','{:url('admin_permission_add')}','520','440')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a></span> <span class="r">共有数据：<strong>{$countt}</strong> 条</span> </div>
		<table class="table table-border table-bordered table-bg">
			<thead>
				<tr>
					<th scope="col" colspan="7">权限节点</th>
				</tr>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="40">ID</th>
					<th width="200">权限名称</th>
					<th>URL地址</th>
					<th>菜单状态</th>
					<th>排序</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				{foreach name="store_menu_level_list" item="vo"}
				<tr class="text-c">
					<td><input type="checkbox" value="{$vo.id}" name="chkid"></td>
					<td>{$vo.id}</td>
					<td style="text-align: left;">{neq name="vo.level" value="1"}|{php}for($i=1;$i
						<$vo[ 'level'];$i++){echo ' ----';}{/php}{/neq}{$vo.name}</td>
							<td>{$vo.title}</td>
							<td>
								{if condition="$vo.status eq 1"}
								<a class="red" href="javascript:;" onclick="permission_state({$vo.id},2);">
									<span class="label label-success radius">已启用</span>
								</a>
								{else/}
								<a class="red" href="javascript:;" onclick="permission_state({$vo.id},1);">
									<span class="label label-danger">禁用</span>
								</a>
								{/if}
							</td>
							<td>{$vo.sort}</td>
							<td>
								<a title="编辑" href="javascript:;" onclick="admin_permission_edit('管理员编辑','{:url('users/admin_permission_edit',['id'=>$vo.id])}','500','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
								<a title="删除" href="javascript:;" onclick="admin_permission_del(this,{$vo.id})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
				</tr>
				{/foreach}
			</tbody>
		</table>
	</div>
	{include file="public/footer" /}
	<script type="text/javascript">
		function chk(obj) {
			var  aa  =  document.getElementsByName("chkid");      
			var  str  =  "";      
			for (var  i  =  0;  i  <  aa.length;  i++)  {       
				if (aa[i].checked)  {        
					str  +=  aa[i].value + ",";     
				}       
			}
			var newstr = str.substring(0, str.length - 1);

			layer.confirm('确认要删除吗？', {
				btn: ['确定', '取消'] //按钮
			}, function() {
				$.ajax({
					type: 'get',
					url: "{:url('users/admin_permission_ddel')}",
					dataType: 'json',
					data: {
						newstr: newstr
					},
					success: function(data) {
						if(data.code == 200) {
							window.location.href = "";
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						} else {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						}
					},
					error: function(data) {
						console.log(data.msg);
					}
				});
			});
		}
		/*管理员-权限-添加*/
		function admin_permission_add(title, url, w, h) {
			layer_show(title, url, w, h);
		}
		/*管理员-权限-编辑*/
		function admin_permission_edit(title, url, w, h) {
			layer_show(title, url, w, h);
		}

		/*管理员-权限-删除*/
		function admin_permission_del(obj, id) {
			layer.confirm('确认要删除吗？', {
				btn: ['确定', '取消'] //按钮
			}, function() {
				$.ajax({
					type: 'get',
					url: "{:url('users/admin_permission_del')}",
					dataType: 'json',
					data: {
						id: id
					},
					success: function(data) {
						if(data.code == 200) {
							$(obj).parents("tr").remove();
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						} else {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						}
					},
					error: function(data) {
						console.log(data.msg);
					}
				});
			});
		}

		/*权限-启用*/
		function permission_state(id, status_id) {
			layer.confirm('确认要修改状态吗？', {
				btn: ['确定', '取消'] //按钮
			}, function() {
				$.ajax({
					type: 'get',
					url: "{:url('users/permission_state')}",
					dataType: 'json',
					data: {
						id: id,
						status_id: status_id
					},
					success: function(data) {

						if(data.code == 200) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							}, function() {
								location.reload();
							});
						} else {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							});
						}
					},
					error: function(data) {
						console.log(data.msg);
					}
				});
			});
		}
	</script>